/*
 *
 * SimplePCR1000 (Qt4) Version 1.x
 * Copyright (C) 2011  Tyler H. Jones (me@tylerjones.me)
 * http://www.thebasementserver.com/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */


#ifndef DATABASE_H
#define DATABASE_H

#include "common.h"

class Database : public QObject
{
    Q_OBJECT
public:
    explicit Database(QObject *parent = 0);
    bool Connect();
    bool Disconnect();
    QStringList GetAllChannels();
    QString GetMode(QString freq);
    QString GetFilter(QString freq);
    bool GetHang(QString freq);
    bool GetLockout(QString freq);
    bool RemoveAllChannels(); //Remove ALL Channels
    bool RemoveChannels(const QStringList& freqs);
    bool AddChannel(QString freq);
    bool EditChannel(QString old_freq, QString new_freq);
    void LockoutChannel(QString freq, bool lo);
    void HangChannel(QString freq, bool hang);
    bool CheckChannelExists(QString freq);
    int ChannelCount();
    //Settings properties
    QVariant getConf(QString name, bool DoNotModify=false);
    bool setConf(QString name, QVariant value, bool DoNotModify=false);
    QString mappPath;

private:
    QSqlDatabase db;
    Common COM; //Common varialbes/opertions class declaration
    QVariant formatFromDB(QString name, QVariant val);
    QVariant formatToDB(QString name, QVariant val);

signals:
    void Error(int errnum, QString caller);

};

#endif // DATABASE_H
